package com.doitedu.day06

import scala.collection.Map
import scala.util.Random

/**
 * @Date: 22.6.26 
 * @Author: HANGGE
 * @qq: 598196583
 * @Tips: 学大数据 ,到多易教育
 * @Description:
 * 类型匹配
 *   1 值
 *   2 数据类型   List(x,y...)    List[Int]   (x,y,_,_)  (x:Int,_,_,_)  (x:Int,_,y:String,_)  Map  User
 */
object _02模式匹配_值匹配 {
  def main(args: Array[String]): Unit = {
    val list1 = List(1,2,3)
    val list2 = List(11,22,33 ,4,5)
    val tp1 = (1,"zss",23,"M")
    val tp2 = (1,"lss",23)

    val ls = List[Double](1,2,3,4,5,6,7,8)
    val ls2 = List[String]("hello" , "scala" , "java","java")
   // matchValuePlus(new User)


  }

  def matchValuePlus(arg:Any): Unit ={
    arg match {
      case  "hello" =>println("你的参数是hello")
      case  1 =>println("你的参数是1")
      // 集合类型  集合中的元素的个数 三个元素的List集合可以匹配到
      case List(x,y,z)=>println(s"$x -- $y -- $z")
      // 根据元素的个数匹配值
      case (id,name,age,gerder) =>println(s"$name")
      // 如果匹配时声明数据类型  判断个数和类型都匹配 才满足
      case (id:String,name:String,age:Int) =>println(s"$name")
      case x:List[Double] =>println(x)
      case x:List[String] =>println(x)
      case x:User=>println("user...")

      case _ =>println("你的参数位置值")
    }
  }



  def matchValue: Unit = {
    val ls = List[Any](1, 2, 3, 4, "hello")

    /**
     * 数值  简单类型的匹配
     */
    ls.map {
      case 1 => println("数字1")
      case 2 => println("数字2")
      case 3 => println("数字3")
      case "hello" => print("这是是hello")
      case _ => println("太大了...")
    }
  }
}
